package com.md.util;

import java.io.UnsupportedEncodingException;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

import org.apache.commons.codec.digest.DigestUtils;

public class Md5Util {
	
	public static String doEncrypt(Map<String, Object> head,Map<String, Object> body,String appKey) {
		Map<String,Object> map =new HashMap<String, Object>();
		map.putAll(head);
		map.putAll(body);
		Object[] keys =  map.keySet().toArray();
		Arrays.sort(keys);
		StringBuilder originStr = new StringBuilder();
		for(Object key:keys){
			if(null!=map.get(key)&&!"".equals(map.get(key).toString()))
			originStr.append(key).append("=").append(map.get(key)).append("&");
		}
		originStr.append("key=").append(appKey);
		System.out.println(originStr.toString());
		String sign ="";
		try {
			sign = DigestUtils.md5Hex(originStr.toString().getBytes("utf-8"));
		} catch (UnsupportedEncodingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return sign;
	}
}
